/*
 * Copyright (c) 2023. bmy
 * Email：2271608011@qq.com
 * Github：https://github.com/helpcode
 */
import VueRouter from 'vue-router';

export default class NavigationGuardsUtils {

  public beforeEach(Router: VueRouter) : void {
    Router.beforeEach((to, from, next) => {
      document.title = to.meta && to.meta.title;
      if (to.meta && to.meta.isLogin) {
        if (localStorage.getItem("moehu_token") != null) {
          next()
        } else {
          next({
            path: '/login'
          })
        }
      } else {
        if (localStorage.getItem("moehu_token") != null
          && to.path == "/login") {
          Router.back();
        }
        next()
      }
    });
  }

  public afterEach(Router: VueRouter) : void {
    Router.afterEach((to, from) => {
      console.log("Router.afterEach")
    })
  }

}